package com.lxy.util;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisUtil {

    @Autowired
    RedisTemplate redisTemplate;


    //专门简化对redis数据库中字符串类型数据的操作
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * 判断指定key中的filed是否存在
     * @param key
     * @param field
     * @return
     */
    public boolean hexists(String key, int field) {
        HashOperations<String, String, String> hashOperations = stringRedisTemplate.opsForHash();
        String str = hashOperations.get(key, field);
        return str == null ? false : true;
    }

    public String hset(String key,String filed){
        return (String) stringRedisTemplate.opsForValue().get(key);
    }


}
